


public class AdditiveExpr extends EqualityExpr {

	MultiplicativeExpr multiExpr;
	AdditiveExpr addExpr;
	int op;


	public AdditiveExpr() {

	}

	public void check() throws SemanticException {
		multiExpr.check();
		if (addExpr != null)
			addExpr.check();
		checkType();
	}

	public int checkType() throws SemanticException {
		if (addExpr != null) {
			// check both the same type
			if (addExpr.checkType() != multiExpr.checkType())
				throw new SemanticException(
						"Types of expression doesn't match: "
								+ addExpr.checkType() + " , "
								+ multiExpr.checkType());
			// check it is floar or int only
			int type = multiExpr.checkType();
			if (type != Type.NM) {
				System.out.println(type);
				throw new SemanticException(
						"Arethmetic expression can be done only on int or float");
			}
		}
		return multiExpr.checkType();
	}

	public AdditiveExpr(MultiplicativeExpr multiExpr, AdditiveExpr addExpr,
			int op) {
		super();
		this.multiExpr = multiExpr;
		this.addExpr = addExpr;
		this.op = op;
	}

	public String toString() {
		String ret = "AdditiveExpression\n";
		String s = "";
		if (addExpr != null)
			s += addExpr.toString() + (op == Type.PO ? "+" : "-") + "\n";
		s += multiExpr.toString();
		for (String st : s.split("\n"))
			ret += "| " + st + "\n";
		return ret;
	}
}
